package com.mobileares.midp.widgets.client.icon;

import com.google.gwt.event.dom.client.*;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;

/**
 * Created by IntelliJ IDEA.
 * User: Tom
 * Date: 2011-4-2
 * Time: 9:14:00
 * To change this template use File | Settings | File Templates.
 */
public class Icon extends Composite {
    private Anchor icon;
    private String imageDefault;
    private String imageOver;

    public Icon(String imageDefault, String imageOver) {
        this.imageDefault = imageDefault;
        this.imageOver = imageOver;
        icon = new Anchor();
        initWidget(icon);
        DOM.setStyleAttribute(icon.getElement(),"backgroundImage","url("+imageDefault+")");
        init();
    }

    private void init() {
        icon.addMouseOverHandler(new MouseOverHandler() {
            public void onMouseOver(MouseOverEvent event) {
                DOM.setStyleAttribute(icon.getElement(),"backgroundImage","url("+imageOver+")");
            }
        });
        icon.addMouseOutHandler(new MouseOutHandler() {
            public void onMouseOut(MouseOutEvent event) {
                DOM.setStyleAttribute(icon.getElement(),"backgroundImage","url("+imageDefault+")");

            }
        });
        icon.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                DOM.setStyleAttribute(icon.getElement(),"backgroundImage","url("+imageDefault+")");

            }
        });
    }

    public void addClickHandler(ClickHandler handler) {
        icon.addClickHandler(handler);
    }
}
